package protocol.JT808_2011;

import java.util.HashMap;

public class Handle808_2011JT08 implements IHandle808_2011JT {

    @Override
    public String handle(JT808_2011Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0800(cmd);
            case 0x01:
                return handle0801(cmd);
            case 0x02:
                return handle0802(cmd);
            default:
                return "808-2011:未匹配的命令字"+(cmd.readOrder()+","+cmd.subOrder());
        }
    }

    private String handle0802(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:存储多媒体数据检索应答");
        builder.append("\r\n");
        builder.append("应答流水号:"+cmd.readInt(2));
        builder.append("\r\n");

        int size = cmd.readInt(2);
        builder.append("检索总项数据总项数:"+size);
        builder.append("\r\n");

        for (int i = 0; i < size; i++) {
            HashMap<Integer,String> list = new HashMap<>();
            list.put(0,"图像");
            list.put(1,"音频");
            list.put(2,"视频");
            int type = cmd.readInt(1);
            builder.append("多媒体类型（"+type+"):"+list.getOrDefault(type,"未定义"));
            builder.append("\r\n");

            builder.append("通道ID:"+cmd.readInt());
            builder.append("\r\n");

            list.clear();
            list.put(0,"平台下发指令");
            list.put(1,"定时动作");
            list.put(2,"抢劫报警触发");
            list.put(3,"碰撞侧翻报警触发");

            type = cmd.readInt(1);
            builder.append("事件项编码（"+type+"):"+list.getOrDefault(type,"未定义"));
            builder.append("\r\n");

            JT808_2011Utils.handle0200ALL(builder,cmd);
        }

        return builder.toString();
    }

    private String handle0801(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:多媒体事件信息上传");
        builder.append("\r\n");

        builder.append("多媒体数据ID："+cmd.readDWORD());
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图像");
        list.put(1,"音频");
        list.put(2,"视频");
        int type = cmd.readInt(1);
        builder.append("多媒体类型（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"JPEG");
        list.put(1,"TIF");
        list.put(2,"MP3");
        list.put(3,"WAV");
        list.put(4,"WMV");

        type = cmd.readInt(1);
        builder.append("多媒体格式编码（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"平台下发指令");
        list.put(1,"定时动作");
        list.put(2,"抢劫报警触发");
        list.put(3,"碰撞侧翻报警触发");

        type = cmd.readInt(1);
        builder.append("事件项编码（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("通道ID:"+cmd.readInt());
        builder.append("\r\n");

        builder.append("多媒体数据包:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0800(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:多媒体事件信息上传");
        builder.append("\r\n");

        builder.append("多媒体数据ID："+cmd.readDWORD());
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图像");
        list.put(1,"音频");
        list.put(2,"视频");
        int type = cmd.readInt(1);
        builder.append("多媒体类型（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"JPEG");
        list.put(1,"TIF");
        list.put(2,"MP3");
        list.put(3,"WAV");
        list.put(4,"WMV");

        type = cmd.readInt(1);
        builder.append("多媒体格式编码（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"平台下发指令");
        list.put(1,"定时动作");
        list.put(2,"抢劫报警触发");
        list.put(3,"碰撞侧翻报警触发");

        type = cmd.readInt(1);
        builder.append("事件项编码（"+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("通道ID:"+cmd.readInt());
        builder.append("\r\n");

        return builder.toString();
    }
}
